<template>
    <div class="KnowledgeTreeMenu">
        <nav-bar
        :title="'知识库'"
        :isSearch="false"
        ></nav-bar>

        <!-- 面包屑 -->
        <breadcrumb :breadcrumb="breadcrumb" :isKnowledgeTree="false" isCollection></breadcrumb>

        <!-- 侧边导航页面 -->
        <div class="sidebar_content">
            <!-- 侧边导航 -->
            <sidebar :sidebarList="sidebarList" @activeIndex="activeIndex"></sidebar>
            <!-- 侧边栏内容部分 -->
            <content-tagList
            :contentListData="listData[sidebarActiveIndex]"
            :topTitle="sidebarList.length > 0 ? sidebarList[sidebarActiveIndex].label : ''"
            :currentTreeId="currentTreeId"
            ></content-tagList>
        </div>
    </div>
</template>

<script>
import NavBar from 'components/public/NavBar.vue'
import Breadcrumb from 'components/public/Breadcrumb.vue'
import Sidebar from 'components/public/Sidebar.vue'
import ContentTagList from 'components/public/ContentTagList.vue'
export default {
    name: 'KnowledgeTreeMenu',
    components: {
        NavBar,
        Breadcrumb,
        Sidebar,
        ContentTagList
    },
    data(){
        return{
            // 左侧侧边栏当前选中index
            sidebarActiveIndex: 0,
            // 左侧侧边栏数据
            sidebarList: [],
            // 右侧二级树结构数据
            listData: [],

            // 当前选中的侧边栏的treeId
            currentTreeId: {},

            // 面包屑
            breadcrumb: ['知识库']
        }
    },
    created(){
        this.getknowledgeTreeList()
    },
    methods: {
        // 子组件传过来的index
        activeIndex(index, item){
            this.sidebarActiveIndex = index
            // console.log(item)
            this.currentTreeId = item
            // console.log(this.currentTreeId)
        },
        // 求情树结构数据
        getknowledgeTreeList(){
            this.$request({
                method: 'get',
                url: '/api/KnowledgeTree/GetKnowledgeTreeByTreeId',
                params: {
                    Token: sessionStorage.getItem("mobileToken"),
                    treeId: 0,
                    Name: '',
                    FileCategory: '',
                    pageSize: '',
                    pageIndex: ''
                }
            }).then(({data}) => {
                // console.log(data)
                if(data.code == 200){
                    this.sidebarList = data.treeDataList
                    this.currentTreeId = this.sidebarList[0]
                    // console.log(this.currentTreeId)
                    let list = data.treeDataList.map(item => item.children)
                    this.listData = list

                }else{
                    this.$notify('加载数据失败，请重试。')
                }
            })
        }
    },
    computed: {
        
    }
}
</script>

<style lang="less" scoped>
.KnowledgeTreeMenu{
    .sidebar_content{
        margin: 0 -15px;
        position: relative;
        display: flex;
        justify-content: flex-start;
        align-items: flex-start;
    }
}
</style>